﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CoolCode.Web.UI.WebControls
{
    public class ColumnTemplate : ITemplate
    {
        private DataControlRowType templateType;

        private string columnName;

        private string cId;

        public ColumnTemplate(DataControlRowType type, string colname, string controlId)
        {
            templateType = type;
            columnName = colname;
            cId = controlId;
        }

        public void InstantiateIn(System.Web.UI.Control container)
        {
            switch (templateType)
            {
                case DataControlRowType.Header:
                    // Create the controls and set id properties to put in the header
                    Literal myHeadLiteral = new Literal();
                    myHeadLiteral.ID = cId;
                    myHeadLiteral.Text = "<B>" + columnName + "</B>";
                    container.Controls.Add(myHeadLiteral);
                    break;
                case DataControlRowType.DataRow:
                    //// Create the controls and set id properties to put in a data row
                    LinkButton lb = new LinkButton { ID = cId , CommandName = columnName  };
                    container.Controls.Add(lb);
                    //TextBox myTextBox = new TextBox();
                    //myTextBox.ID = cId;
                    //myTextBox.DataBinding += new EventHandler(this.TextBoxDataBinding);
                    //container.Controls.Add(myTextBox);
                    break;
                default:
                    // Insert code to handle unexpected values.
                    break;
            }
        }

        //private void TextBoxDataBinding(Object sender, EventArgs e)
        //{
        //    TextBox myTextBox = (TextBox)sender;
        //    GridViewRow row = (GridViewRow)myTextBox.NamingContainer;
        //    myTextBox.Text = DataBinder.Eval(row.DataItem, columnName).ToString();
        //}

    }
}
